/*
 * Copyright (c) 2019. seven studio. @chengdu
 * seven studio in chengdu by lb
 * this project for snmp tool
 */

package com.xlx.openLink.threadtask;

import com.xlx.openLink.dao.DeviceMapper;
import com.xlx.openLink.dao.PortMapper;
import com.xlx.openLink.service.SpeedService;
import com.xlx.openLink.threadtask.workservice.SearchSpeedService;
import com.xlx.openLink.vo.DevicePortVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 计算网速
 * @author Admin
 */
@Component
@Slf4j
public class DiscoverCalcSpeedTask {


    @Autowired
    private DeviceMapper deviceMapper;

    @Autowired
    SearchSpeedService searchSpeedService;


    @Scheduled(fixedDelay = 5 * 1000)
    @Transactional
    public void calcSpeed() {
        log.info("计算网速-------------------------开始");
        long start = System.currentTimeMillis();
        //获取全部的端口
        List<DevicePortVO> devicePortVOList = deviceMapper.selectDevPortList();
        try {
            searchSpeedService.SearchSpeed(devicePortVOList);
        } catch (Exception e) {
            log.info(e.toString());
        }
        long time = System.currentTimeMillis() - start;
        double stime = (double) time / 1000;
        log.info("计算网速--------------------time is " + stime + "s");
    }
}
